<template>
  <div>
    <el-container v-if="item">
      <el-aside width="200px">
        <el-menu
          router
          :default-active="$route.path"
          class="el-menu-vertical-demo"
        >
          <div>
            <img style="width=50%" src="../assets/logo-text.svg" alt="" />
          </div>
          <el-menu-item
            :index="`/root/${x.path}`"
            v-for="(x, i) in data"
            :key="i"
          >
            <i :class="x.i"></i>
            <span slot="title">{{ x.name }}</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="user">
            <span>欢迎 &nbsp;:&nbsp;{{ item.uname }}&nbsp;&nbsp;</span>
            <el-avatar
              src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
            ></el-avatar
            >&nbsp;&nbsp;&nbsp;
            <el-button type="primary" @click.native="back" round
              >退出</el-button
            >
          </div>
        </el-header>
        <el-main style="line-height: 10px"><router-view /></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      item: [],
      data: [
        {
          path: "home",
          i: "el-icon-s-home",
          name: "首页",
        },
        {
          path: "rootuser",
          i: "el-icon-s-custom",
          name: "用户管理",
        },
        {
          path: "rootstyle",
          i: "el-icon-collection",
          name: "菜品管理",
        },
      ],
    };
  },
  methods: {
    back() {
      localStorage.setItem("token", "");
      this.$message({
        message: "退出成功",
        type: "success",
      });
      this.$router.push("/rootlogin");
    },
    getData() {
      let phone = localStorage.token;
      this.axios
        .get("http://127.0.0.1:3000/data/users/rootuser?uphone=" + phone)
        .then((res) => {
          this.item = res.data.data[0];
        });
    },
  },
  mounted() {
    this.getData();
  },
};
</script>

<style lang="scss" scoped>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  height: 100vh;
  user-select: none;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}
.user {
  float: right;
  display: flex;
  height: 60px;
  align-items: center;
  justify-items: center;
}
</style>
